Drop table if exists "LabParameterHeader" cascade;
create table "LabParameterHeader"(
		 "LabParameterHeaderId" serial primary key,
		 "ParameterName" text,
		 "DisplayName" text,
		 "ReferenceOutput" text,
		 "Active" bool default true,
		 "CreatedBy" int references "Account"("AccountId"),
		 "CreatedDate" timestamp without time zone,
		 "ModifiedBy" int references "Account"("AccountId"),
		 "ModifiedDate" timestamp without time zone
);

Drop table if exists "LabParameterDetail" cascade;

create table "LabParameterDetail"(
			"LabParameterDetailId" bigserial primary key,
			"LabParameterHeaderId" int references "LabParameterHeader"("LabParameterHeaderId" ),
			"Gender" varchar(30) default null,
			"FromAge" int default null,
			"FromAgeType" varchar(250) default null,
			"ToAge" int default null,
			"ToAgeType" varchar(250) default null,
			"MinValue" numeric(8,2) default null,
			"MaxValue" numeric(8,2) default null,
			"MinCriticalValue" numeric(8,2) default null,
			"MaxCriticalValue" numeric(8,2) default null,
			"UnitId" int references "LookupValue"("LookupValueId")
);

Drop table if exists "LabComponentHeader" cascade;

create table "LabComponentHeader"(
 	"LabComponentHeaderId" serial primary key,
 	"ComponentName" text,
 	"ComponentId" text,
 	"Active" bool default true, 	
	"CreatedBy" int4 null REFERENCES "Account"("AccountId"),
	"CreatedDate" timestamp NULL,
	"ModifiedBy" int4 null REFERENCES "Account"("AccountId"),
	"ModifiedDate" timestamp NULL
);

Drop table if exists "LabComponentDetail" cascade;

create table "LabComponentDetail"(
			"LabComponentDetailId" serial primary key,
			"LabComponentHeaderId" int references "LabComponentHeader"("LabComponentHeaderId"),
			"LabParameterHeaderId" int references "LabParameterHeader"("LabParameterHeaderId"),
			"Priority" int
);